<?php
/**
* feedback相关逻辑
*
* @author     Robot
* @version    1.0
* @package    Base Framework
* @access     public
* @copyright  商业软件,受著作权保护
* @link       http://***
*/
class feedbackModule extends Base
{
	/**
	 * 构造函数
	 *
	 */
	public function __construct(){}

	/**
	 * 提交反馈
	 * 
	 */
	public function add($arr)
	{
		//log所有提交
		Common::log2file(var_export($arr, true), CACHE_DIR."log/post/feedback_".date("Ymd").".log");

		//打分
		$xing['xing_zhuanyexing'] = $arr['xing_zhuanyexing'];
		$xing['xing_kexindu'] = $arr['xing_kexindu'];
		$xing['xing_yiyongxing'] = $arr['xing_yiyongxing'];
		$xing['xing_zhunquedu'] = $arr['xing_zhunquedu'];
		$xing['xing_zhidetuijian'] = $arr['xing_zhidetuijian'];

		//反馈不含中文
		if(!Common::getCn($arr['ganshou']) || !Common::getCn($arr['jianyi']))
		{
			return false;
		}

		//联系方式为空
		if(!$arr['email'] || !$arr['phone'] || !$arr['username'])
		{
			return false;
		}

		$oDto = new DTO_User_Feedback();
		$oDto->pmecuser = $arr['username'];
		$oDto->email = $arr['email'];
		$oDto->contact = $arr['phone'];
		$oDto->ganshou = $arr['ganshou'];
		$oDto->jianyi = $arr['jianyi'];
		$oDto->dafen = Common::encode($xing);
		$oDto->ip = Common::getIpSimple();
		$oDto->createtime = time();
		$oDto->ip = Common::getIpSimple();
		$oDto->state = 1;

		$oDmo = new DMO_User_Feedback();
		if(!$oDmo->exist($oDto, 'email,ganshou'))
		{
			if(!$oDmo->add($oDto))
			{
				throw new MyException("Err001");
			}
		}

		return true;
	}

	/**
	* 列出反馈
	*
	* @access public
	* @param  void
	* @return void
	*/
	public function listFeedback($oPage)
	{
		$aKey = array("state"=>"1");
		$aOrder = array("id"=>"desc");

		$oDmo = new DMO_User_Feedback();
		$aRes = $oDmo->getPage($oPage->getBegin(), $oPage->PerPage, $aKey, $aOrder);
		$oPage->Count = $oDmo->getTotal();

		$aInfoid = array();
		if($aRes)
		{
			foreach($aRes as $key => $val)
			{
				$aRes[$key]['ipname'] = Common::getIpLocation($val['ip']);
			}
		}

		return $aRes;
	}

	/**
	* 查看反馈
	*
	* @access public
	* @param  void
	* @return void
	*/
	public function getFeedback($id)
	{
		$aKey = array("id"=>$id);
		$oDmo = new DMO_User_Feedback();
		$aRes = $oDmo->getRow($aKey);
		if($aRes)
		{
			$aRes['ipname'] = Common::getIpLocation($aRes['ip']);
			$aRes['dafen'] = Common::decode($aRes['dafen']);
			foreach($aRes['dafen'] as $key => $val)
			{
				switch(substr($key, 5))
				{
					case "zhuanyexing" : $aRes['dafen']["专业性"] = str_pad("", 3*$val, "★");
					case "kexindu" : $aRes['dafen']["可信度"] = str_pad("", 3*$val, "★");
					case "yiyongxing" : $aRes['dafen']["易用性"] = str_pad("", 3*$val, "★");
					case "zhunquedu" : $aRes['dafen']["准确度"] = str_pad("", 3*$val, "★");
					case "zhidetuijian" : $aRes['dafen']["值得推荐"] = str_pad("", 3*$val, "★");
				}
				unset($aRes['dafen'][$key]);
			}
		}

		//标记为已查看
		$oDto = new DTO_User_Feedback();
		$oDto->id = $id;
		$oDto->isread = 1;
		$oDmo->setField("isread");
		if(!$oDmo->modify($oDto))
		{
			throw new Exception("Err001");
		}

		return $aRes;
	}

	/**
	 * 删除反馈
	 * 
	 */
	public function delFeedback($id)
	{
		//标记为已删除
		$oDto = new DTO_User_Feedback();
		$oDto->id = $id;
		$oDto->state = 0;

		$oDmo = new DMO_User_Feedback();
		$oDmo->setField("state");
		if(!$oDmo->modify($oDto))
		{
			throw new Exception("Err001");
		}

		//记录日志
		$this->admin_managerModule->addLog(10, "删除", "[反馈]id=".$id);

		return true;
	}
}

?>